package com.siberhus.easyexecutor;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MethodInvoker {
	
	private Object targetObject;
	
	private Method targetMethod;

	private Object arguments[];
	
	public MethodInvoker(Object targetObject){
		this.targetObject = targetObject;
	}
	
	public void invoke() throws Throwable{
		try {
			if(arguments!=null){
				targetMethod.invoke(targetObject,arguments);
			}else{
				targetMethod.invoke(targetObject);
			}
		} catch (InvocationTargetException e) {
			throw e.getTargetException();
		}
	}

	public Object getTargetObject() {
		return targetObject;
	}

	public void setTargetObject(Object targetObject) {
		this.targetObject = targetObject;
	}

	public Method getTargetMethod() {
		return targetMethod;
	}

	public void setTargetMethod(Method targetMethod) {
		this.targetMethod = targetMethod;
	}

	public Object[] getArguments() {
		return arguments;
	}

	public void setArguments(Object[] arguments) {
		this.arguments = arguments;
	}
	
	
}